package com.xps.charminguser.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.Nullable;

import com.xps.charminguser.R;
import com.xps.charminguser.utils.SharedPreferencesUtils;

import butterknife.ButterKnife;

/**
 * Created by XPS on 2017/9/12.
 */

public class SlashActivity extends Activity implements Handler.Callback {
    private static final int HANDLER_JUDGE = 0;
    private Handler handler = null;
    private static final String PREFS_NAME = "MyUserInfo";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        HandlerThread handlerThread = new HandlerThread("backgrondThread");
        handlerThread.start();
        handler = new Handler(handlerThread.getLooper(), this);
        handler.sendEmptyMessageDelayed(HANDLER_JUDGE, 100);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        handler.removeCallbacksAndMessages(null);
        handler.getLooper().quit();
    }

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case HANDLER_JUDGE:
                if (SharedPreferencesUtils.getBoolean("isSave", "boolean", false)) {
                    startActivity(new Intent(SlashActivity.this, MainActivity.class));
                } else {
                    startActivity(new Intent(SlashActivity.this, LoginActivity.class));
                }
                finish();
                break;
        }
        return true;
    }
}
